{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d28b669c",
   "metadata": {},
   "source": [
    "-------\n",
    "* 本学习记录人：陈依玟\n",
    "* 学习时间： 2121-11-02\n",
    "* week 10\n",
    "* 本记录主要参考文档\n",
    "> 1. [Python官方文档]（https://docs.python.org/3/）\n",
    ">> 1. [Tutorial] (https://docs.python.org/3/tutorial/index.html)\n",
    ">> 2. [Library Reference] (https://docs.python.org/3/library/index.html)\n",
    "> 2. [徐老师博客]（https://www.cnblogs.com/xuzhichao/p/11407192.html）\n",
    "> 3. [python在线学习平台] （https://app.datacamp.com/learn）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0161bfd6",
   "metadata": {},
   "source": [
    "#  本周学习内容\n",
    "\n",
    "## 1. 字符串和数值的一般方法\n",
    "\n",
    "> 1.[字符串概念]（https://docs.python.org/3/tutorial/introduction.html#strings）\n",
    ">> 1. single quotes('...')\n",
    ">> 2. double quotes(\"...\")\n",
    ">> 3. <font style= <\"color：red\">\"\"\"...\"\"\"or'''...'''</front :不修改文本样式\n",
    ">> 4. 字符串的拼接：strl+str2,连接变量或变量和文字，请使用+\n",
    ">> 5. 字符串的索引性质（**index**） ：字符串可以被索引（下标），第一个字符的索引为0\n",
    ">> 6. 字符串的切片（**slice**）： [start:stop]\n",
    ">>> * 案例：\n",
    "  ```\n",
    "  +---+---+---+---+---+---+\n",
    " | P | y | t | h | o | n |\n",
    " +---+---+---+---+---+---+\n",
    " 0   1   2   3   4   5   6\n",
    "-6  -5  -4  -3  -2  -1\n",
    "```\n",
    "\n",
    ">> 6. 字符串的切片(**slice**) : [start:stop]\n",
    "> 2. [字符串的一般方法] (https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5fed3aec",
   "metadata": {},
   "source": [
    " ### 2.数值\n",
    " \n",
    " > 1.Python 作为运算器，了解一般的运算符\n",
    " > 2.了解运算符的先后顺序"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "56ae8ea8",
   "metadata": {},
   "source": [
    "## 2.[for循环遍历]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7e68c811",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'p'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"python\"\n",
    "text[0] # index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "62b65bbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'y'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[1] # index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "eac8f0a1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'py'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text[0:2] # slice 右边的值取不到"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fc79be09",
   "metadata": {},
   "source": [
    "#### 1.1字符串的一般方法\n",
    "\n",
    "* 应掌握：\n",
    "> 1.知道str的方法使用一般操作str.methods_name()\n",
    "> 2.了解Python的字符串官方网站查询位置\n",
    "> 3.能够在后续遇到字符串问题时能找到解决方法\n",
    "> 4.了解常见方法： count，capitalize，isdigit,format,strip,split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "a01abe1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Python'"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# str.capitalize（）\n",
    "# 返回字符串的副本，其中第一个字符大写，其余字符小写\n",
    "text.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "361f3fcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'     python    '"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# str.center(width)    width 是一个 数值   \n",
    "text.center(15)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "eeb16307",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (<ipython-input-23-ab6af5803b6b>, line 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-23-ab6af5803b6b>\"\u001b[1;36m, line \u001b[1;32m2\u001b[0m\n\u001b[1;33m    text_center = \"Return centered in a string of length width.Padding is done using the specified fillchar (default is an ASCII space).The original\u001b[0m\n\u001b[1;37m                                                                                                                                                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "#str.count（）\n",
    "text_center = \"Return centered in a string of length width.Padding is done using the specified fillchar (default is an ASCII space).The original\n",
    "text_center.count(\"string\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "1e467d56",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# str.isdigit() 判断字符串是否是数值   False不是数值 True 是数值\n",
    "text_center.isdigit()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7da46efb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'evenc'"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "text = \"evenchan\"\n",
    "text[3]\n",
    "text[0:5]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "2e8d4c7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Evenchan'"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# str.capitalize（）\n",
    "text.capitalize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "84d82efc",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-19-d95bb52e2e07>, line 5)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-19-d95bb52e2e07>\"\u001b[1;36m, line \u001b[1;32m5\u001b[0m\n\u001b[1;33m    for i in rang(5)：\u001b[0m\n\u001b[1;37m                    ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "# 1.for循环\n",
    "# 2. range()\n",
    "# 总结:\n",
    "\n",
    "for i in rang(5)：\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a0de61b8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "p\n",
      "y\n",
      "h\n",
      "t\n",
      "o\n",
      "n\n"
     ]
    }
   ],
   "source": [
    "for chr in \"pyhton\":\n",
    "    print(chr)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f55cc3d5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# range :范围,10代表：1.10个数值，2.终止点10\n",
    "# 只有一个值：   stop（终止值）：10  step（步长）：1（默认）\n",
    "# range可以生成一组序列数值，如：10，生成10个数，从0开始，每次+1\n",
    "list(range(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "82ae7841",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid syntax (<ipython-input-20-d3f7882a974b>, line 7)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-20-d3f7882a974b>\"\u001b[1;36m, line \u001b[1;32m7\u001b[0m\n\u001b[1;33m    for i in range(96)\u001b[0m\n\u001b[1;37m                      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n"
     ]
    }
   ],
   "source": [
    "# 实践：获取（抓取）学校所有新闻页面链接\n",
    "# 用到的知识点 ： 1. 变量 ,赋值   2. 字符串  3.条件判断    4.for 循环     5.range\n",
    "# 南方学院 学校要闻\n",
    "学校域名 = \"https://www.nfu.edu.cn/\"\n",
    "学校要闻 = \"xxyw/\"\n",
    "校园动态 = \"\n",
    "学校要闻第一页 = 学校域名 + 学校要闻 + \"index\" +\".htm\"\n",
    "for i in range(96)\n",
    "    if i == 0:\n",
    "        print(学校域名 + 学校要闻 + \"index\" + \"0\" + \".htm\" )\n",
    "    else:\n",
    "        print((学校域名 + 学校要闻 + \"index\" + str(i) + \".htm\")\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "83e465f0",
   "metadata": {},
   "source": [
    "> 1.rang可以每次生成一个序列\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "e8a5331a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 只有两个值：start：5 stop（终止值）：10  step（步长）:1(默认)\n",
    "# 只有一个值：star:0（默认） sto\n",
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3b42ecbf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "9cd0c8e9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 3, 6, 9]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6299111e",
   "metadata": {},
   "source": [
    "### 2.random模块（随机数）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "d4e35464",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 调用模块\n",
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "12e038d4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.13212693380452878"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.random()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "7ccf768f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "28"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "round(random.random()*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "8c794802",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 给定数值范围\n",
    "random.randint(1,6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "7263db1f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "5\n",
      "3\n",
      "6\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "# 摇骰子\n",
    "for i in range(5):\n",
    "    print(random.randint(1,6))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "add500e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18\n",
      "41\n",
      "37\n",
      "56\n",
      "87\n",
      "48\n",
      "95\n",
      "53\n"
     ]
    }
   ],
   "source": [
    "# 福利彩票生成器\n",
    "本次开奖 = \"15,25,39,48,80,92,97,88\"\n",
    "import random\n",
    "for i in range(8):\n",
    "    print(round(random.random()*100))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "c8be4a77",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'CYW'"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 随机点名 choice\n",
    "import random\n",
    "最可爱的人= [\"CYW\",\"LXT\",\"XM\"]\n",
    "random.choice(最可爱的人) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "474a60b8",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-37-d20b6c665254>, line 10)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-37-d20b6c665254>\"\u001b[1;36m, line \u001b[1;32m10\u001b[0m\n\u001b[1;33m    print('当前时间节点的秒数：'，right_tis_second)\u001b[0m\n\u001b[1;37m                                      ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    " # range决定了执行的次数\n",
    "    right_this_second =datetime.today().second\n",
    "    print('当前时间节点的秒数：'，right_tis_second)\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    print('等待的时间：',wait_time')\n",
    "    print（\"---------------\"）\n",
    "    time.sleep.(wait_time)\n",
    "          "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "f54ddae4",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "当前时间节点的秒数： 36\n",
      "Not an odd second.\n",
      "等待的时间： 3\n",
      "--------------------\n",
      "当前时间节点的秒数： 39\n",
      "This second seems a little odd.\n",
      "等待的时间： 2\n",
      "--------------------\n",
      "当前时间节点的秒数： 41\n",
      "This second seems a little odd.\n",
      "等待的时间： 5\n",
      "--------------------\n",
      "当前时间节点的秒数： 46\n",
      "Not an odd second.\n",
      "等待的时间： 1\n",
      "--------------------\n",
      "当前时间节点的秒数： 47\n",
      "This second seems a little odd.\n",
      "等待的时间： 1\n",
      "--------------------\n"
     ]
    }
   ],
   "source": [
    "from datetime import datetime\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):\n",
    "    # range决定了执行的次数\n",
    "    right_this_second = datetime.today().second\n",
    "    print('当前时间节点的秒数：',right_this_second)\n",
    "    if right_this_second in odds:\n",
    "        print(\"This second seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd second.\")\n",
    "    wait_time = random.randint(1,5)\n",
    "    print('等待的时间：',wait_time)\n",
    "    print(\"--------------------\")\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb03d64d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
